package com.yuchen.bearrecord.controller;

import com.yuchen.bearrecord.config.Result;
import com.yuchen.bearrecord.entity.Drug;
import com.yuchen.bearrecord.service.impl.DrugServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/drug")
public class DrugController {
    @Resource
    private DrugServiceImpl drugService;

    @GetMapping("/drugDetail")
    @ResponseBody
    public Result getDrugDetail(@RequestParam("id") Long id){
        return drugService.getDrugDetail(id);
    }

    @GetMapping("/drugList")
    @ResponseBody
    public Result getDrugList(){
        return drugService.getDrugList();
    }

    @GetMapping("/getSelectDrugs")
    @ResponseBody
    public Result getSelectDrugs(){
        return drugService.getSelectDrugs();
    }

    @GetMapping("/expireList")
    @ResponseBody
    public Result getExpireList(){
        return drugService.getExpireDrugs();
    }

    @GetMapping("/searchDrug")
    @ResponseBody
    public Result getSearchList(@RequestParam("keyword") String keyword){
        return drugService.searchDurgs(keyword);
    }

    @PostMapping("/addDrug")
    @ResponseBody
    public Result addBook(@RequestBody Drug drug) {
        return drugService.addDrug(drug);
    }

    @DeleteMapping("/deleteDrug")
    @ResponseBody
    public Result deleteDrug(@RequestParam("id") Long id) {
        return drugService.deleteDrug(id);
    }

    @PutMapping("/updateDrug")
    @ResponseBody
    public Result updateDrug(@RequestBody Drug drug) {
        return drugService.updateDrug(drug);
    }

    @PutMapping("/updateDrugSurplus")
    @ResponseBody
    public Result updateDrugSurplus(@RequestBody Drug drug) {
        return drugService.updateDrugSurplus(drug);
    }

    @DeleteMapping("/clearDrugs")
    @ResponseBody
    public Result clearDrugs() {
        return drugService.clearDrugs();
    }

    @GetMapping("/userDrugList")
    @ResponseBody
    public Result getUserDrugList(@RequestParam("openid") String openid){
        return drugService.getUserDrugList(openid);
    }

    @DeleteMapping("/deleteUserDrug")
    @ResponseBody
    public Result deleteUserDrug(@RequestParam("id") Long id) {
        return drugService.deleteUserDrug(id);
    }

    @PutMapping("/updateUserDrug")
    @ResponseBody
    public Result updateUserDrug(@RequestBody Drug drug) {
        return drugService.updateUserDrug(drug);
    }
}
